<?php
include_once($_SERVER['DOCUMENT_ROOT'] . '/mba/models/MBA.php');
include_once($_SERVER['DOCUMENT_ROOT'] . '/mba/controls/CapNhatDonViController.php');
?>

<script type="text/javascript">


// funtion lay gia tri tu radio button "chon"
    function getValue(id) {
        document.capnhatdonvi.txtmadv.value = document.getElementById("madv" + id).innerHTML;
        document.capnhatdonvi.txttendv.value = document.getElementById("tendv" + id).innerHTML;
        document.capnhatdonvi.txtdiachidv.value = document.getElementById("diachidv" + id).innerHTML;
        document.capnhatdonvi.txtlienhedv.value = document.getElementById("lienhedv" + id).innerHTML;
        document.capnhatdonvi.txttentk.value = document.getElementById("tentk" + id).innerHTML;
        document.capnhatdonvi.txtmatkhau.value = document.getElementById("matkhau" + id).innerHTML;
        document.capnhatdonvi.txtquyen.value = document.getElementById("quyen" + id).innerHTML;
        // chuyen mau cac textfield tendv,diachidv,lienhedv thanh mau trang', va cho phep sua doi thong tin
        document.capnhatdonvi.txtmadv.readOnly = true;
        document.capnhatdonvi.txtmadv.style.backgroundColor = '#cccccc';
        document.capnhatdonvi.txttendv.style.backgroundColor = '#FFFFFF';
        document.capnhatdonvi.txtdiachidv.style.backgroundColor = '#FFFFFF';
        document.capnhatdonvi.txtlienhedv.style.backgroundColor = '#FFFFFF';
        document.capnhatdonvi.txttentk.style.backgroundColor = '#FFFFFF';
        document.capnhatdonvi.txtmatkhau.style.backgroundColor = '#FFFFFF';
        document.capnhatdonvi.btnsuadv.disabled = false;
        document.capnhatdonvi.btnxoadv.disabled = false;
        document.capnhatdonvi.txttendv.readOnly = false;
        document.capnhatdonvi.txtdiachidv.readOnly = false;
        document.capnhatdonvi.txtlienhedv.readOnly = false;
        document.capnhatdonvi.txttentk.readOnly = false;
        document.capnhatdonvi.txtmatkhau.readOnly = false;
        document.capnhatdonvi.txtquyen.disabled = false;
    }

// fuction hien bang xac nhan truoc khi xoa don vi
    function confirmDelete() {
        if (confirm("Bạn có chắc muốn xóa đơn vị này không?")) {
            return true;
        }
        return false;
    }



</script>

<!doctype html>
<html>
    <head>
        <meta charset=utf-8 />
        <title>Cập nhật đơn vị</title>
        <style type="text/css">

        </style><link href="../css/style.css" rel="stylesheet" type="text/css">
        <link href="../SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css">
        <script src="../SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
    </head>

    <body>
     
        <div class="bodyStyle">
            <p>
            <form name="capnhatdonvi" method="post" action="">
                <!-- bang hien thi -->  
                <table align="center" class="font" width="450" border="0" cellspacing="0" cellpadding="0">
                    <tr bgcolor="#dae9f3">

                        <td align=center class=TableHeader  height="35" >Cập Nhật Đơn vị </td>
                    </tr>
                    <tr bgcolor="#dae9f3">
                        <td class="border_1" colspan="3" valign="top"><table width="450" border="0" align="center">

                                <tr>
                                    <td>Mã đơn vị </td>
                                    <td colspan="3" align="left"><input name="txtmadv" type="text" id="txtmadv" style="background-color:#CCCCCC" size="10" maxlength="100" readonly ><br>

                                    </td>
                                </tr>
                                <tr>
                                <tr>
                                    <td>Tên đơn vị </td>
                                    <td colspan="3"><input name="txttendv" type="text" id="txttendv"  style="background-color:#CCCCCC" size="40" maxlength="100" readonly ><br>

                                    </td>
                                </tr>        

                                <tr>
                                    <td> Địa chỉ đơn vị </td>
                                    <td align="left" style="font-size: 12;"><input name="txtdiachidv" type="text" id="txtdiachidv"  style="background-color:#CCCCCC" size="40" maxlength="100" readonly /></td>

                                <tr>
                                    <td>Thông tin liên hệ </td>
                                    <td colspan="3"><input name="txtlienhedv" type="text" id="txtlienhedv" style="background-color:#CCCCCC" size="40" maxlength="100" readonly >
                                        <br></td>
                                </tr>
                                <tr>
                                    <td>Tên tài khoản</td>
                                    <td colspan="3"><input name="txttentk" type="text" id="txttentk" style="background-color:#CCCCCC" size="40" maxlength="100" readonly >
                                        <br></td>
                                </tr>
                                <tr>
                                    <td>Mật khẩu</td>
                                    <td colspan="3"><input name="txtmatkhau" type="text" id="txtmatkhau" style="background-color:#CCCCCC" size="40" maxlength="100" readonly ></td>
                                </tr>
                                <tr>
                                    <td>Quyền</td>
                                    <td colspan="3"><label for="txtquyen"></label>
                                        <select name="txtquyen" id="txtquyen" disabled>
                                            <option value="0" selected></option>
                                            <option value="1">Phòng KH-KT (1)</option>
                                            <option value="2">Đơn vị thành viên (2)</option>
                                            <option value="3">Đơn vị nhập số liệu (3)</option>            
                                        </select></td>
                                </tr>
                                <tr>

                                    <?php
                                    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
                                        $madv = $_POST['txtmadv'];
                                        $tendv = $_POST['txttendv'];
                                        $diachidv = $_POST['txtdiachidv'];
                                        $lienhedv = $_POST['txtlienhedv'];
                                        $tentk = $_POST['txttentk'];
                                        $matkhau = $_POST['txtmatkhau'];
                                        $quyen = $_POST['txtquyen'];

                                        echo "<script language=\"javascript\">";
                                        echo "document.capnhatdonvi.txtmadv.value='$madv';";
                                        echo "document.capnhatdonvi.txttendv.value='$tendv';";
                                        echo "document.capnhatdonvi.txtdiachidv.value='$diachidv';";
                                        echo "document.capnhatdonvi.txtlienhedv.value='$lienhedv';";
                                        echo "document.capnhatdonvi.txttentk.value='$tentk';";
                                        echo "document.capnhatdonvi.txtmatkhau.value='$matkhau';";
                                        echo "document.capnhatdonvi.txtquyen.value='$quyen';";
                                        echo "</script>";
                                    }
                                    ?>
                                </tr>

                                <tr>
                                    <td colspan="4" class="btn" id="btn" >
                                        <input type="submit" name="btnthemdv" id="btnthemdv" value="Thêm đơn vị">
                                        <input type="submit" name="btnsuadv" id="btnsuadv" value="Sửa đơn vị" disabled="true">
                                        <input type="submit" name="btnxoadv" id="btnxoadv" value="Xóa đơn vị"  disabled="true" onClick="confirmDelete()">
                                    </td>
                                </tr>
                            </table></td>
                    </tr>
                </table>
                </br>

                <!-- lay du lieu tu bang don vi va hien thi -->
                <?php
                $donvi = new DonVi();
                $result = $donvi->dsDonVi();
                echo "<table align='center' width='900' border='2' cellspacing='0' cellpadding='0' ";
                echo "<tr >";
                echo "<td align='center'>Danh sách máy biến áp</td>";
                echo "</tr>";
                echo "<tr >";
                echo "<td colspan='3' valign='top'><table width='900' border='2' cellpadding='0' cellspacing='0'>";
                echo "<tr>";
                echo "<td width='30' align='center' >STT</td>";
                echo "<td width='400' align='center' >Mã số tài sản </td>";
                echo "<td width='800' align='center' >Số N0 </td>";
                echo "<td width='800' align='center' >Mã điện áp </td>";
                echo "<td width='600' align='center' >Mã loại </td>";
                echo "<td width='600' align='center' >Công suất </td>";
                echo "<td width='600' align='center' >NSX </td>";
                echo "<td width='600' align='center' >Thông số đo </td>";
                echo "<td width='600' align='center' >Nhận xét </td>";
                echo "<td width='50' align='center' >Chọn</td>";
                echo "</tr>";




                $num = mysql_num_rows($result);
                $i = 0;
                echo "<tbody style='display:none;'>";
                while ($row = mysql_fetch_array($result)) {
                    $i++;
                    echo "</tbody>";
                    echo "<tr>";
                    echo "<td align='center' >" . $i . "</td>";
                    echo "<td  align='center'><div id='madv$i'>" . $row['MA_DON_VI'] . "</div></td>";
                    echo "<td  align='left'><div id='tendv$i'>" . $row['TEN_DON_VI'] . "</div></td>";
                    echo "<td  align='left'><div id='diachidv$i'>" . $row['DIA_CHI_DV'] . "</div></td>";
                    echo "<td  align='left'><div id='lienhedv$i'>" . $row['LIEN_HE_DV'] . "</div></td>";
                    echo "<td  align='left'><div id='tentk$i'>" . $row['TEN_TK'] . "</div></td>";
                    echo "<td  align='left'><div id='matkhau$i'>" . $row['MAT_KHAU'] . "</div></td>";
                    echo "<td  align='left'><div id='quyen$i'>" . $row['QUYEN'] . "</div></td>";
                    echo "<td  align='center'><input type='radio' name='chkchon' value='$i' onClick='getValue(this.value);' ></td>";
                    echo "</tr>";
                }
                echo "</tbody>";

                echo "<tr>";
                echo "<td align='left' colspan='9'><span style=' color:#008000'>Tổng số đơn vị: $num";

                echo "</span></td>";
                echo "<td align='right' colspan='2'><font color='green'>";
                echo "</font></td>";
                echo "</tr>";
                echo "</table></td>";
                echo "</tr>";
                echo "</table>";
                //}
                ?>
            </form>
            <!-- het bang -->
        </p>
        <p>&nbsp;
        </p>
    </div>
</body>
</html>
